/*
* $Id: EventManager.cpp 143 2010-09-09 19:55:18Z volok-aleksej@yandex.ru $
*
* Copyright 2008-2009 by Volokitin Alexey
* All rights reserved
*
*/
#include "Common/include.h"
#include "EventManager.h"

#include "Common/RefObject.h"
CRefObject<CEventManager> g_EventManager;
IEventManager* IEventManager::GetEventManager(){
	return g_EventManager.GetObject();
}

CEventManager::CEventManager(){}
CEventManager::~CEventManager(){}

void CEventManager::SendEvent(int nIdEvent){
	for(std::vector<ISubscriber*>::iterator it = m_aEventSubscribers[nIdEvent].begin(); it != m_aEventSubscribers[nIdEvent].end(); it++){
		(*it)->EventHandler();
	}
}

void CEventManager::SubscribeEvent(ISubscriber* pSubscriber, int nIdEvent){
	m_aEventSubscribers[nIdEvent].push_back(pSubscriber);
}

void CEventManager::UnSubscribeEvent(ISubscriber* pSubscriber, int nIdEvent){
	for(std::vector<ISubscriber*>::iterator it = m_aEventSubscribers[nIdEvent].begin(); it != m_aEventSubscribers[nIdEvent].end(); it++){
		if(*it == pSubscriber){
			m_aEventSubscribers[nIdEvent].erase(it);
			break;
		}
	}
}
